package com.spotify.analysis.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.spotify.analysis.dto.GenreDTO;
import lombok.Data;
import java.util.List;

@Data
@TableName("track")
public class Track {
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String artistName;
    private String trackName;
    private String trackId;
    private Integer popularity;
    private Integer year;
    private String genre;
    private Integer danceability;
    private Integer energy;
    @TableField("`key`")
    private Integer key;


    // 获取艺术家列表，按 "&" 分割
    public List<String> getArtistNames() {
        if (artistName != null && !artistName.isEmpty()) {
            return List.of(artistName.split("&"));
        }
        return List.of();
    }
    // 设置艺术家列表，用 "&" 连接
    public void setArtistNames(List<String> artistNames) {
        if (artistNames != null && !artistNames.isEmpty()) {
            this.artistName = String.join("&", artistNames);
        } else {
            this.artistName = "";
        }
    }

    public GenreDTO convertToDTO() {
        GenreDTO dto = new GenreDTO();
        dto.setId(this.getId());
        dto.setArtistName(this.getArtistNames());
        dto.setTrackName(this.getTrackName());
        dto.setTrackId(this.getTrackId());
        dto.setPopularity(this.getPopularity());
        dto.setYear(this.getYear());
        dto.setGenre(this.getGenre());
        dto.setDanceability(this.getDanceability());
        dto.setEnergy(this.getEnergy());
        dto.setKey(this.getKey());
        return dto;
    }
}